﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using ModuleDALCore;
namespace DAL
{
    public class DICHVUDAO:DALBase
    {
        public DICHVUDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPDICHVU"; }
            set { _SpName = value; }
        }
        public DataTable GetListDV()
        {
            dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new DICHVU(), null), ConvertClassToArray.GetValues(new DICHVU(), 0));
				return dt;
			}
			catch { return null; }
        }
        public List<DICHVU> GetListDVs()
        {
            dt = new DataTable();
            List<DICHVU> benhnhanc = new List<DICHVU>();
            try
            {

                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new DICHVU(), null), ConvertClassToArray.GetValues(new DICHVU(), 0));
                benhnhanc = (List<DICHVU>)ConvertDatatableToList.ConvertTo<DICHVU>(dt);
                return benhnhanc;
            }
			catch { return null; }
        }
		public DICHVU GetDVByID(DICHVU dv)
		{
			dt = new DataTable();
			DICHVU tmp = new DICHVU();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 6));
				tmp = (DICHVU) ConvertDatatableToList.ConvertToObject<DICHVU>(dt);
				return tmp;
			}
			catch { return null; }
		}
        public DataTable Find(DICHVU dv)
        {
            
            dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 5));

				return dt;
			}
			catch { return null; }
        }
        public List<DICHVU> Finds(DICHVU dv)
        {

            dt = new DataTable();
            List<DICHVU> benhnhanc = new List<DICHVU>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 5));
				benhnhanc = (List<DICHVU>)ConvertDatatableToList.ConvertTo<DICHVU>(dt);
				return benhnhanc;
			}
			catch { return null; }
        }
        public String CreatenewId()
        {
			try
			{
				return "DV" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new DICHVU(), null), ConvertClassToArray.GetValues(new DICHVU(), 1));

			}
			catch { return null; }
        }
        public bool INSERT(DICHVU cv)
        {

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

			}
			catch { return false; }
        }
        public bool UPDATE(DICHVU cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

            }
            catch { return false;}
        }
        public bool DELETE(DICHVU cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

            }
            catch { return false;}
        }
    }
}
